/**
 * Created by Dalyn on 2017/6/6.
 */
import React from "react";
import Relay from "react-relay";
import Util from "../../../../../util/Util";
import { Table, Button, Icon, Modal, message, Input } from 'antd';
import OrderPaymentRecordMutation from './mutation/OrderPaymentRecordMutation';
import "./css/Payment.css";

export default class MaterialBill extends React.Component{
    constructor(props) {
        super(props);
        this.state = {
            pageSize: 100,
            pageNum: 1,
            totalResult: "",
            loading: true,
        };
        this.planIdsDel = [];
    }

    componentWillMount(){
        let {pageSize,pageNum} = this.state;
        this.getPlanDetailByOrderId(pageSize,pageNum)
    }
    /*拉取表格数据*/
    getPlanDetailByOrderId(pageSize,pageNum) {
        Relay.Store.commitUpdate(
            new OrderPaymentRecordMutation({
                pageSize:pageSize,
                pageNum: pageNum,
                orderId:this.props.orderId,
                // orderId:"TD20170605150000019815",
            }),
            {
                onFailure: () => {
                    message.error("网络请求失败")
                    this.setState({
                        loading: false
                    })
                },
                onSuccess: (response) => {
                    let errorCode = response.orderPaymentRecord.data.errorCode;
                    if (errorCode == 0) {
                        let PaymentRecord = response.orderPaymentRecord.data.orderPaymentRecordDomainList;
                        this.setState({
                            dataSource: PaymentRecord,
                            loading: false
                        })
                    } else{
                        this.setState({
                            loading: false
                        });
                        if(errorCode == 500){
                            message.error('服务器错误，请联系系统管理员')
                        }
                    }
                }

            }
        );
    }
    /*页码*/
    onSure(size,num){
        this.setState({
            pageSize: size,
            pageNum: num,
            loading:true,
        }, this.myRelay)
    }
    render(){
        let { dataSource,proDigestModel} = this.state;
        const { value, editable } = this.state;
        const columns = [
            {
                title: '付款时间',
                dataIndex: 'createTime',
                key: 'createTime',
                render: (text, record) =>{
                    return(
                        <span>{Util.dateFormat(record.createTime)}</span>
                    )
                }
            },
            {
                title: '订单金额',
                dataIndex: 'orderMoney',
                key: 'orderMoney',
                render: (text, record) =>{
                    return(
                        <span>{Util.doubleFormat(record.orderMoney)}</span>
                    )
                }
            },
            {
                title: '付款金额',
                dataIndex: 'payment',
                key: 'payment',
                render: (text, record) =>{
                    return(
                        <span>{Util.doubleFormat(record.payment)}</span>
                    )
                }
            },
            {
                title: '累计付款金额',
                dataIndex: 'totalPurchaseMoney',
                key: 'totalPurchaseMoney',
                render: (text, record) =>{
                    return (
                        <span>{Util.doubleFormat(record.totalPurchaseMoney)}</span>
                    )
                }
            }
        ];
        return (
            <div>
                <Table
                    columns={columns}
                    dataSource={dataSource}
                    // bordered
                    className="order_table"
                    pagination={false}
                    style={{width:'100%',marginTop:"0"}}
                    loading={this.state.loading}
                    rowKey={record =>record.paymentRecordId}
                />
                {/*<Pagination eachSize={this.state.pageSize} dataSize={this.state.totalResult} onSure={this.onSure.bind(this)} ref={'pagination'}/>*/}
            </div>
        )
    }
}
